import 'dart:async';

import 'package:FiduMart/screen/home/register_view.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:get/get.dart';


import 'dart:io';

import '../../app_routes.dart';
import '../../constants/color_constant.dart';
import '../../core/network/RequestClient.dart';
import '../../widget/custom_image_view.dart';


class LoginDialog extends StatefulWidget {
  // LoginDialog();

  @override
  State<LoginDialog> createState() => _LoginDialogState();
}

class _LoginDialogState extends State<LoginDialog> {
  // Page1Controller controller = Get.find<Page1Controller>();
  var obscureText = true.obs;

  final emailController = TextEditingController();
  final pwdController = TextEditingController();


  @override
  void initState() {
    super.initState();

  }

  @override
  Widget build(BuildContext context) {
    return  new_loginView();
  }

  Widget new_loginView(){
    return SingleChildScrollView(
      child: Container(
        decoration: BoxDecoration(
            borderRadius: BorderRadius.only(
                topLeft: Radius.circular(10),
                topRight: Radius.circular(10)
            ),
            color: Colors.white
        ),
        padding: EdgeInsets.only(left: 20, right: 20, bottom: 30, top: 10),
        child: Column(
          mainAxisSize: MainAxisSize.min, // 使内容尽量紧凑
          children: <Widget>[
            Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: [
                Text('Login please'.tr,style: TextStyle(fontSize: 18,fontWeight: FontWeight.bold,color: Colors.black),),

              ],
            ),
            SizedBox(
              height: 30,
            ),
            TextField(
              controller: emailController,
              style: TextStyle(color: Colors.black),
              decoration: InputDecoration(
                filled: true, // 背景填充
                fillColor: ColorConstant.colorFFF5F6F9,

                hintText: 'input email',
                hintStyle:TextStyle(color: ColorConstant.colorFFA2A2A2),
                contentPadding: EdgeInsets.all(15),
                border: OutlineInputBorder(
                  borderRadius: BorderRadius.circular(10),
                  borderSide: BorderSide.none, // 边框样式
                ),
              ),
            ),
            SizedBox(height: 20), // 用于添加输入框之间的间隔
            Obx(() => TextField(
              controller: pwdController,
              style: TextStyle(color: Colors.black),
              decoration: InputDecoration(
                filled: true,
                fillColor: ColorConstant.colorFFF5F6F9,

                hintStyle:TextStyle(color: ColorConstant.colorFFA2A2A2),
                hintText: 'input password',
                contentPadding: EdgeInsets.all(15),
                suffixIcon: GestureDetector(
                    onTap: () {
                      obscureText.value = !obscureText.value;
                    },
                    child: Icon(
                      obscureText.value
                          ? Icons.visibility_off
                          : Icons.visibility,
                      color: ColorConstant.colorFFA2A2A2,// 密码可见性切换图标
                    )),
                // 密码可见性切换图标
                border: OutlineInputBorder(
                  borderRadius: BorderRadius.circular(10),
                  borderSide: BorderSide.none,
                ),
              ),
              obscureText: obscureText.value, // 密码隐藏
            ),),
            SizedBox(
              height: 25,
            ),
            //渐变色背景按钮
            GestureDetector(
              onTap: () async{
                if (emailController.text.isEmpty ||
                    pwdController.text.isEmpty) {
                  Fluttertoast.showToast(
                    msg: 'Enter the complete content',
                  );
                  return;
                }
                await RequestClient().setToken("1234567890987654321qwertyuuio");
                Get.offAllNamed(AppRoutes.home1);

              },
              child: Container(
                  height: 40,
                  // width: 140,
                  decoration: BoxDecoration(
                    borderRadius: BorderRadius.circular(5),
                    gradient: LinearGradient(
                      colors: [
                        ColorConstant.colorFFD405EF,
                        ColorConstant.colorFF052BFD
                      ],
                      begin: Alignment.centerLeft, // 渐变色开始位置
                      end: Alignment.centerRight, // 渐变色结束位置
                    ),
                  ),
                  alignment: Alignment.center,
                  child: Text(
                    'login'.tr,
                    style: TextStyle(fontSize: 14,color: Colors.white),
                  )),
            ),
            SizedBox(
              height: 15,
            ),
            Row(
              mainAxisAlignment: MainAxisAlignment.center,
              children: [
                Text('no account?',style: TextStyle(color: ColorConstant.text_grey),),
                GestureDetector(
                  onTap: () {
                    Get.back();
                    Get.bottomSheet(isScrollControlled:true,RegisterDialog());
                  },
                  child: Text(
                    "register now",
                    style: TextStyle(
                        color: ColorConstant.colorFFAD4AFF,
                        fontSize: 15,
                        decoration: TextDecoration.underline,
                        decorationColor: ColorConstant.colorFFAD4AFF),
                  ),
                ),
              ],
            ),

            SizedBox(
              height: 35,
            ),
          ],
        ),
      ),
    );
  }


}
